import { segment } from "oicq";
import plugin from '../../lib/plugins/plugin.js'
import cfg from '../../lib/config/config.js';
/**
 * Created with Visual Studio Code.
 * Description: 因为没有，所以才有
 * User: kirito
 * Date: 2022-11-05
 * Time: \(^o^)/ 17:45:17 摆烂！
 * Blog: mywifeasuna.top
 */

export class fuck extends plugin {
  constructor () {
    super({
      name: '日群友',
      dsc: '随机给一位群友注射脱氧核糖核酸',
      event: 'message',
      priority: 5000,
      rule: [
        {
          reg: '^#?(日群友|透群友)$',
          fnc: 'fuck'
        },
        {
          reg: '^#?(日群主|透群主)$',
          fnc: 'fuckowner'
        },
        {
          reg: '^#?(日管理|透管理)$',
          fnc: 'fuckadmin'
        },
        {
          reg: '^日(他|她)(.*)$',
          fnc: 'ri',
        },
        {
          reg: '^#?日我$',
          fnc: 'fuckme'
        }
      ]
    })
  }

  async fuck (e) {
      console.log("用户命令：", e.msg);
      let num = Math.round(Math.random() * 100);
      // let num = 11;  // 测试 
      if (num <= 5) {
        let msg = [segment.at(e.user_id), "你也配？自己默默导管吧！"]
        e.reply(msg);
      } else if (num <= 10) {
        let msg = [segment.at(e.user_id), "呜呜呜，只因无力(╯‵□′)╯︵┻━┻，你直接日歪了，细狗"]
        e.reply(msg);
      } else if (num <= 11) {
        let msg = [segment.at(e.user_id), "万中无一，孤独终老。\n\n（这么低的概率也能命中请速速去抽卡买彩票，作者都想不到会有人能中~）"]
        e.reply(msg);
      } else if (num <= 75) {
        let map = await e.group.getMemberMap();
        let arrMember = Array.from(map.values());
        let mem = arrMember[Math.round(Math.random() * (arrMember.length-1))];
        let msg = [segment.at(e.user_id), "成功给" + mem.nickname + "注射了脱氧核糖核酸~", segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${mem.user_id}`)]
        e.reply(msg);
      } else if (num > 75) {
        let map = await e.group.getMemberMap();
        let arrMember = Array.from(map.values());
        let mem = arrMember[Math.round(Math.random() * (arrMember.length-1))];
        let msg = ["恭喜你", segment.at(e.user_id), "和" + mem.nickname + "喜结良缘❤", segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${mem.user_id}`)]
        e.reply(msg);
      }
  }
  
  async fuckowner (e) {
    console.log("用户命令：", e.msg);
    let map = await e.group.getMemberMap();
    let arrMember = Array.from(map.values());
    if (e.group.pickMember(e.user_id).is_owner) {
      let msg = ["尊狗的贵群主，你要日你自己？", segment.at(e.user_id)]
      e.reply(msg)
    } else {
      let mem = arrMember[Math.round(Math.random() * (arrMember.length-1))];
      while (true) {
        if (e.group.pickMember(mem.user_id).is_owner) {
          let msg = [segment.at(e.user_id), "狠狠的对群主", segment.at(mem.user_id), "注射了脱氧核糖核酸！"]
          e.reply(msg)
          break
        } else {
          mem = arrMember[Math.round(Math.random() * (arrMember.length-1))];
        }
      }
    }
  }

  async fuckadmin (e) {
    console.log("用户命令：", e.msg);
    let map = await e.group.getMemberMap();
    let arrMember = Array.from(map.values());
    if (e.group.pickMember(e.user_id).is_admin) {
      let msg = ["亲狗的爱管理，你要日你自己？", segment.at(e.user_id)]
      e.reply(msg)
    } else {
      let mem = arrMember[Math.round(Math.random() * (arrMember.length-1))];
      while (true) {
        if (e.group.pickMember(mem.user_id).is_admin) {
          let msg = [segment.at(e.user_id), "狠狠的对管理", segment.at(mem.user_id), "注射了脱氧核糖核酸！"]
          e.reply(msg)
          break
        } else {
          mem = arrMember[Math.round(Math.random() * (arrMember.length-1))];
        }
      }   
    }    
  }
  async ri (e) {
    console.log(e)
        if (!e.isGroup) {//不是群聊
            e.reply("就咱俩，你想干嘛？")
            return true;
        }
        if(!e.at&&e.msg){
            e.reply("你要日谁你倒是艾特啊")
            return true;
        }

        if (e.atme && !e.at && !e.atall) return false;
      let master = cfg.masterQQ
      let qq = e.at
    if (master.indexOf(qq) > -1){
      // let name = e.nickname  
      let name = e.message[1].text.replace("@", "")
      let msg = [segment.at(e.user_id), "被" + name + "狠狠地注射了脱氧核糖核酸~", segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.user_id}`)]
      e.reply(msg);}else{
      let name = e.nickname
      let msg = [segment.at(e.at), "被" + name + "狠狠地注射了脱氧核糖核酸~", segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.at}`)]
      e.reply(msg)} 
  
  }
  async fuckme (e) {
    console.log("用户命令：", e.msg);
    if(!e.at){
    let map = await e.group.getMemberMap();
    let arrMember = Array.from(map.values());
    let mem = arrMember[Math.round(Math.random() * (arrMember.length-1))];
    let msg = [segment.at(e.user_id), "被" + mem.nickname + "狠狠地注射了脱氧核糖核酸~", segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${mem.user_id}`)]
    e.reply(msg);
    }else{let name = e.message[1].text.replace("@", "")
    let msg = [segment.at(e.user_id), "被" + name + "狠狠地注射了脱氧核糖核酸~", segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.user_id}`)]
    e.reply(msg)}
}
}